<template>
  <el-dialog :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="商家" prop="sellerId"><el-input v-model="dataForm.sellerId" placeholder="商家"></el-input></el-form-item>
      <el-form-item label="账单类型（0现付1信用卡授权2消费）" prop="payType">
        <el-input v-model="dataForm.payType" placeholder="账单类型（0现付1信用卡授权2消费）"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="creatTime"><el-input v-model="dataForm.creatTime" placeholder="创建时间"></el-input></el-form-item>
      <el-form-item label="金额" prop="payPrice"><el-input v-model="dataForm.payPrice" placeholder="金额"></el-input></el-form-item>
      <el-form-item label="银行" prop="banks"><el-input v-model="dataForm.banks" placeholder="银行"></el-input></el-form-item>
      <el-form-item label="账号" prop="banksNumber"><el-input v-model="dataForm.banksNumber" placeholder="账号"></el-input></el-form-item>
      <el-form-item label="参考号" prop="referenceNumber"><el-input v-model="dataForm.referenceNumber" placeholder="参考号"></el-input></el-form-item>
      <el-form-item label="有效期" prop="termValidity"><el-input v-model="dataForm.termValidity" placeholder="有效期"></el-input></el-form-item>
      <el-form-item label="同住id" prop="peopleId"><el-input v-model="dataForm.peopleId" placeholder="同住id"></el-input></el-form-item>
      <el-form-item label="备注" prop="remarks"><el-input v-model="dataForm.remarks" placeholder="备注"></el-input></el-form-item>
      <el-form-item label="押金类型为现付（0AR帐1现金2储值卡3积分兑换4银行卡5支付宝6微信）" prop="nowType">
        <el-input v-model="dataForm.nowType" placeholder="押金类型为现付（0AR帐1现金2储值卡3积分兑换4银行卡5支付宝6微信）"></el-input>
      </el-form-item>
      <el-form-item label="0未结账1已结账2已转出" prop="type"><el-input v-model="dataForm.type" placeholder="0未结账1已结账2已转出"></el-input></el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        sellerId: '',
        payType: '',
        creatTime: '',
        payPrice: '',
        banks: '',
        banksNumber: '',
        referenceNumber: '',
        termValidity: '',
        peopleId: '',
        remarks: '',
        nowType: '',
        type: ''
      },
      dataRule: {
        sellerId: [{ required: true, message: '商家不能为空', trigger: 'blur' }],
        payType: [{ required: true, message: '账单类型（0现付1信用卡授权2消费）不能为空', trigger: 'blur' }],
        creatTime: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
        payPrice: [{ required: true, message: '金额不能为空', trigger: 'blur' }],
        banks: [{ required: true, message: '银行不能为空', trigger: 'blur' }],
        banksNumber: [{ required: true, message: '账号不能为空', trigger: 'blur' }],
        referenceNumber: [{ required: true, message: '参考号不能为空', trigger: 'blur' }],
        termValidity: [{ required: true, message: '有效期不能为空', trigger: 'blur' }],
        peopleId: [{ required: true, message: '同住id不能为空', trigger: 'blur' }],
        remarks: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
        nowType: [{ required: true, message: '押金类型为现付（0AR帐1现金2储值卡3积分兑换4银行卡5支付宝6微信）不能为空', trigger: 'blur' }],
        type: [{ required: true, message: '0未结账1已结账2已转出不能为空', trigger: 'blur' }]
      }
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinaccounting/info/${this.dataForm.id}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.sellerId = data.tHotelFloorRoomCheckinAccounting.sellerId;
              this.dataForm.payType = data.tHotelFloorRoomCheckinAccounting.payType;
              this.dataForm.creatTime = data.tHotelFloorRoomCheckinAccounting.creatTime;
              this.dataForm.payPrice = data.tHotelFloorRoomCheckinAccounting.payPrice;
              this.dataForm.banks = data.tHotelFloorRoomCheckinAccounting.banks;
              this.dataForm.banksNumber = data.tHotelFloorRoomCheckinAccounting.banksNumber;
              this.dataForm.referenceNumber = data.tHotelFloorRoomCheckinAccounting.referenceNumber;
              this.dataForm.termValidity = data.tHotelFloorRoomCheckinAccounting.termValidity;
              this.dataForm.peopleId = data.tHotelFloorRoomCheckinAccounting.peopleId;
              this.dataForm.remarks = data.tHotelFloorRoomCheckinAccounting.remarks;
              this.dataForm.nowType = data.tHotelFloorRoomCheckinAccounting.nowType;
              this.dataForm.type = data.tHotelFloorRoomCheckinAccounting.type;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinaccounting/${!this.dataForm.id ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              sellerId: this.dataForm.sellerId,
              payType: this.dataForm.payType,
              creatTime: this.dataForm.creatTime,
              payPrice: this.dataForm.payPrice,
              banks: this.dataForm.banks,
              banksNumber: this.dataForm.banksNumber,
              referenceNumber: this.dataForm.referenceNumber,
              termValidity: this.dataForm.termValidity,
              peopleId: this.dataForm.peopleId,
              remarks: this.dataForm.remarks,
              nowType: this.dataForm.nowType,
              type: this.dataForm.type
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: this.$t('Common.OperationSuccessful'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit('refreshDataList');
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
